﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace IllustratedCsharp7_ch10
{
    class chapt10_15MultipleResourcesAndNesting
    {

        static void Main()
        {
            using (TextWriter tw1 = File.CreateText("Lincoln.txt"),
                              tw2 = File.CreateText("Fraklin.txt"))
            {
                tw1.WriteLine("Four score and seven years ago,...");
                tw2.WriteLine("Early to bed;Early to rise ...");
            }

            //using语句嵌套
            using (TextWriter tw1 = File.CreateText("Lincoln.txt"))
            {
                tw1.WriteLine("Four score and seven years ago,...");

                using (TextWriter tw2 = File.CreateText("Frankin.txt"))
                    tw2.WriteLine("Early to bed;Early to rise ...");
            }

            using (TextReader tr1 = File.OpenText("Lincoln.txt"),
                             tr2 = File.OpenText("Fraklin.txt"))
            {
                string InputString;
                while (null != (InputString = tr1.ReadLine()))
                    Console.WriteLine(InputString);

                while (null != (InputString = tr2.ReadLine()))
                    Console.WriteLine(InputString);

            }
        }
        
    }
}
